<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id="i1" placeholder="请输入~100之间的整数" >
<input type="button" value="猜一猜" onclick="f()">
<div>结果:<span></span></div>

<script>
  //得到0~100随机整数
  let x = parseInt(Math.random()*101);
  let count=0;
  function f() {
    let i1 = document.querySelector("#i1");
    let num = document.querySelector("span");
    if(isNaN(i1.value)){
      num.innerText="输入有误！";
      return;
    }
      count++;
      if(i1.value<x){
        num.innerText="猜小了"
      }else if(i1.value>x){
        num.innerText="猜大了！"
      }else{
        num.innerText="猜对了,共猜了"+count+"次";
        count =0;
        x = parseInt(Math.random()*101);
      }


  }
</script>
</body>
</html>